package cn.zhaoyuening.hadoopdemo.utils;

import org.apache.commons.math3.analysis.function.Sin;
import org.apache.hadoop.conf.Configuration;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

public class ConfigureFactory {
    private static Configuration configuration = null;

    public static Configuration getConfiguration() {
        if (configuration == null) {
            try {
                configuration = new Configuration();
                InputStream in = ConfigureFactory.class.getClassLoader().getResourceAsStream("hadoop.properties");
                Properties properties = new Properties();
                properties.load(in);
                in.close();
                for (Object key :
                        properties.keySet()) {
                    configuration.set((String)key,properties.getProperty((String) key));
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return configuration;
    }


}
